package com.xggstudio.crm.ui.mvp.v;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.xggstudio.crm.R;
import com.xggstudio.crm.base.BaseActivity;
import com.xggstudio.crm.ui.mvp.v.adapter.CommonAdapter;
import com.xggstudio.crm.ui.mvp.v.adapter.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class UserListActivity extends BaseActivity {

    private Toolbar toolbar;

    private TabLayout tablayout;

    private RecyclerView list;

    private TextView bar_text;

    private CommonAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_user_mager_list;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

        initView();
        initadattper();
    }

    @SuppressLint("RestrictedApi")
    private void initView(){

        bar_text = (TextView) $(R.id.bar_text);
        toolbar = (Toolbar) $(R.id.toolbar);
        toolbar.setTitle("");
        bar_text.setText(getString(R.string.manger_user));

        setSupportActionBar(toolbar);
        getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        tablayout = (TabLayout) $(R.id.tablayout);
        list = (RecyclerView) $(R.id.list);

    }

    private void initadattper(){
        List<String> data = new ArrayList<>();

        for (int i = 0; i < 6; i++) {
            data.add("");
        }

        adapter = new CommonAdapter<String>(this,R.layout.view_mager_other,data) {

            @Override
            public void convert(ViewHolder holder, String s, int position) {

            }
        };

        list.setLayoutManager(new LinearLayoutManager(this));
        list.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_bar_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
            case R.id.menu_add:
                startToActivity(AddOrEditUserActivity.class);
                break;
        }

        return super.onOptionsItemSelected(item);
    }

}
